博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
核桃说笔记
阅读量:7227 次
发布时间:2019-06-29

本文共 1643 字,大约阅读时间需要 5 分钟。

点击展开看更多内容的效果:

{$answerx['author']}

{$answerx['time']}

部分内容。。。。。。

展开全部

 

搜索关键词高亮显示:公共方法

//srl 7-23 搜索覌點,覌點高亮变色修改function highlightDesc($content, $words, $highlightcolor = 'red') {    $wordlist = explode ( " ", $words );    foreach ( $wordlist as $hightlightword ) {        if (strlen ( $content ) < 1 || strlen ( $hightlightword ) < 1) {            return $content;        }        $content = preg_replace ( "/$hightlightword/is", "\\0", $content );    }    return $content;}

使用方法:控制器方法:使用上面方法进行高亮显示

//关键词搜索    function get_by_likename($word, $start = 0, $limit = 6) {        $topiclist = array ();        $query = $this->db->query ( "SELECT * FROM " . $this->db->dbprefix . "answer WHERE content like '%$word%' order by id desc LIMIT $start,$limit" );// var_dump($query->result_array ());die;        foreach ( $query->result_array () as $topic ) {            $topic ['title'] = checkwordsglobal ( $topic ['title'] );            $topic ['describtion'] = checkwordsglobal ( $topic ['content'] );            $topic ['title'] = highlightDesc ( $topic ['title'], $word );$topic ['describtion'] = highlightDesc (  strip_tags ( $topic ['content'] ), $word );$topiclist [] = $topic;        }        return $topiclist;    } 剥去字符串中的 HTML 标签:
strip_tags
页面中使用topiclist  函数遍历显示在页面中即可

 

转载于:https://www.cnblogs.com/yszr/p/10736344.html

你可能感兴趣的文章
捷哥说:学什么技术不重要,学精才重要
查看>>
Android匿名共享内存使用简介
查看>>
vue+element-ui获取select的label
查看>>
Don't Trust, Verify
查看>>
熊市到来,对BCH来说未尝不是一件好事
查看>>
测试防盗链
查看>>
《钢铁是怎样炼成的》的读后感作文5000字
查看>>
Python库大全(涵盖了Python应用的方方面面), 建议收藏留用!
查看>>
第15章FTP服务搭建与配置
查看>>
大数据之Linux早课10.16
查看>>
FastDFS分布式文件系统
查看>>
【CentOS 7笔记47】,systemd系统服务管理#
查看>>
Spring Boot 实现 自定义Starter
查看>>
OpenCV之点的表示:Point类
查看>>
连月薪8万的架构师也“外包”了,那我们该怎么办?
查看>>
小公司出身的程序员,面试咋这么难?!
查看>>
基于Lua和C实现的HTTP服务器
查看>>
SpringBoot之旅第二篇-配置
查看>>
python项目实战:win32ui创建普通菜单
查看>>
代理模式
查看>>